<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <form>
        <div>
            <label for="fname">First name: </label>
            <input id="fname" type="text">
        </div>
        <div>
            <label for="lname">Last name: </label>
            <input id="lname" type="text">
        </div>
        <div>
            <input id="submit" type="submit">
        </div>
    </form>
    <p></p>
    <script>
        var form = document.querySelector('form');
        var fname = document.getElementById('fname');
        var lname = document.getElementById('lname');
        var submit = document.getElementById('submit');
        var para = document.querySelector('p');

        form.onsubmit = function(e) {
        if (fname.value === '' || lname.value === '') {
            e.preventDefault();
            para.textContent = 'You need to fill in both names!';
        }
        }
    </script>
</body>
</html>
